package agenceVoyageVirtuel.server.test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import agenceVoyageVirtuel.client.beans.VoyageData;
import agenceVoyageVirtuel.server.DB_Conn;

/**
 * I was building a example class to get the books of the bible from my mysql database
 *
 * Download Bible Database
 * here is where i got the bible sql database
 * http://sourceforge.net/project/showfiles.php?group_id=186532&package_id=249676&release_id=548680
 *
 * @author branflake2267
 *
 */
public class DB_QueryStuff extends DB_Conn {
	/**
	 * constructor
	 */
	public DB_QueryStuff() {
		
	}

	public void queryMyDB() {
		String query = "SELECT idVoyage, destination, reel, tarifVoyage, image FROM t_voyage;";

		// prepare for rpc transport
		List<VoyageData> voyageDatas = new ArrayList<VoyageData>();
		
		try {
			Connection connection = getConn();
			Statement select = connection.createStatement();
			ResultSet result = select.executeQuery(query);
			int i = 0;
			
			while (result.next()) {
				voyageDatas.add(new VoyageData());
				voyageDatas.get(i).setIdVoyage(result.getInt(1));
				voyageDatas.get(i).setDestination(result.getString(2));
				voyageDatas.get(i).setReel(result.getBoolean(3));
				voyageDatas.get(i).setTarifQuotidien(result.getInt(4));
				voyageDatas.get(i).setNomImage(result.getString(5));

				i++;
			}

			// clean up
			result.close();
			connection.close();
		} catch(Exception e) {
			System.err.println("Mysql Statement Error: " + query);
			e.printStackTrace();
		}

		System.out.println();
	}
}
